//
//  HomeHeaderView.m
//  IconMaster
//
//  Created by mac on 2017/7/27.
//  Copyright © 2017年 yangweiwei. All rights reserved.
//

#import "HomeHeaderView.h"
#import "LB3DBannerView.h"
@implementation HomeHeaderView

//- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
//    
//    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
//                
//    }
//    return self;
//}
- (UIImageView *)backGroundImageView{

    if (!_backGroundImageView) {
        _backGroundImageView = [[UIImageView alloc] init];
        _backGroundImageView.image = [UIImage imageNamed:@"backgroundgradient"];
    }
    return _backGroundImageView;
}
- (UIButton *)btnNew{

    if (!_btnNew) {
        _btnNew = [[UIButton alloc] init];
        _btnNew.tag = 101;
        [_btnNew setImage:[UIImage imageNamed:NSLocalizedString(@"new_img_zh", nil)] forState:Normal];
    }
    return _btnNew;
}
- (UIButton *)listbtn{

    if (!_listbtn) {
        _listbtn = [[UIButton alloc] init];
        _btnNew.tag = 102;
        [_listbtn setImage:[UIImage imageNamed:NSLocalizedString(@"hot_img_zh", nil)] forState:Normal];
    }
    return _listbtn;
}
- (UIButton *)privateBtn{

    if (!_privateBtn) {
        _privateBtn = [[UIButton alloc] init];
        _btnNew.tag = 103;
        [_privateBtn setImage:[UIImage imageNamed:NSLocalizedString(@"pri_img_zh", nil)] forState:Normal];
        
    }
    return _privateBtn;
}
//- (ScrollerView_3D *)ffff{
//
//    if (!_ffff) {
//        _ffff = [[ScrollerView_3D alloc] initWithFrame:CGRectMake(0, 64, KWidth, 250*ScreenRatio_Heght) withImgArr:self.imageArray];
//    }
//    return _ffff;
//}
-(void)layoutSubviews{
    [super layoutSubviews];
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.contentView.userInteractionEnabled = YES;
    
//    self.backGroundImageView = [[UIImageView alloc] init];
//    self.backGroundImageView.image = [UIImage imageNamed:@"backgroundgradient"];
    //        self.timeLab.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:self.backGroundImageView];
    self.backGroundImageView.userInteractionEnabled = YES;
    
//    self.scrollerView_ = [[UIView alloc] init];
//    [self.contentView addSubview:self.scrollerView_];
    
//    self.btnNew = [[UIButton alloc] init];
    self.btnNew.tag = 0;
    [self.btnNew addTarget:self action:@selector(buttonAction:) forControlEvents:TouchUPInside];
//    [self.btnNew setImage:[UIImage imageNamed:NSLocalizedString(@"new_img_zh", nil)] forState:Normal];
    [self.contentView addSubview:self.btnNew];
    
//    self.listbtn = [[UIButton alloc] init];
    self.listbtn.tag = 1;
    [self.listbtn addTarget:self action:@selector(buttonAction:) forControlEvents:TouchUPInside];
//    [self.listbtn setImage:[UIImage imageNamed:NSLocalizedString(@"hot_img_zh", nil)] forState:Normal];
    [self.contentView addSubview:self.listbtn];
    
//    self.privateBtn = [[UIButton alloc] init];
    self.privateBtn.tag = 2;
    [self.privateBtn addTarget:self action:@selector(buttonAction:) forControlEvents:TouchUPInside];
//    [self.privateBtn setImage:[UIImage imageNamed:NSLocalizedString(@"pri_img_zh", nil)] forState:Normal];
    [self.contentView addSubview:self.privateBtn];

    self.backGroundImageView.frame = CGRectMake(0, 0, KWidth, 320*ScreenRatio_Heght);
//    [self.imageArray addObject:[UIImage imageNamed:@"banner@2x"]];
//    [self.imageArray addObject:[UIImage imageNamed:@"banner@2x"]];
  
   
    if (self.ffff) {
       [self.ffff setHidden:YES];
    }
    
        self.ffff = [[LB3DBannerView alloc] initWithFrame:CGRectMake(0, 64, KWidth, 250*ScreenRatio_Heght) andImageURLArray:self.imageArray];
        self.ffff.backgroundColor = [UIColor clearColor];
        self.ffff.userInteractionEnabled = YES;
    
        //    ffff.imageArray = self.imageArray;
        
    [self.backGroundImageView addSubview:self.ffff];
    self.ffff.delegate = self;
    self.ffff.isAutoCarousel = YES;
//    }
        
    self.listbtn.frame = CGRectMake((KWidth - 80) / 2, CGRectGetMaxY(self.backGroundImageView.frame), 80, 80);
    NSInteger space = (KWidth - 80*3)/4;
    self.btnNew.frame = CGRectMake(space, CGRectGetMaxY(self.backGroundImageView.frame), 80, 80);
    self.privateBtn.frame = CGRectMake(KWidth - 80 - space, CGRectGetMaxY(self.backGroundImageView.frame), 80, 80);
//    [self.backGroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.mas_top);
//        make.left.equalTo(self.mas_left);
//        make.right.equalTo(self.mas_right);
//        make.height.equalTo(self.mas_right);
//    }];
   
}

+ (instancetype)headerViewWithTAbleView:(UITableView *)tableView{
    
    static NSString *ID = @"orderHeader";
    HomeHeaderView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:ID];
    if (nil == header) {
        header = [[self alloc] initWithReuseIdentifier:ID];
    }
     
    return header;
}
- (void)buttonAction:(UIButton *)button{

    if (button.enabled) {
        for (UIView *btnView in self.contentView.subviews) {
            if ([btnView isKindOfClass:[UIButton class]]) {
              
               
                if (button.tag == 0) {
                    _listbtn.enabled = YES;
                    _btnNew.enabled = NO;
                    _privateBtn.enabled = YES;
                     [_btnNew setImage:[UIImage imageNamed:NSLocalizedString(@"selected_new_ch", nil)] forState:Normal];
                     [_listbtn setImage:[UIImage imageNamed:NSLocalizedString(@"hot_img_zh", nil)] forState:Normal];
                    [_privateBtn setImage:[UIImage imageNamed:NSLocalizedString(@"pri_img_zh", nil)] forState:Normal];
                    
                }
                if (button.tag == 1){
                    _listbtn.enabled = NO;
                    _btnNew.enabled = YES;
                    _privateBtn.enabled = YES;
                    [_listbtn setImage:[UIImage imageNamed:NSLocalizedString(@"selected_list_ch", nil)] forState:Normal];
                     [_btnNew setImage:[UIImage imageNamed:NSLocalizedString(@"new_img_zh", nil)] forState:Normal];
                    [_privateBtn setImage:[UIImage imageNamed:NSLocalizedString(@"pri_img_zh", nil)] forState:Normal];
                }
//                if (button.tag == 2){
//                    _listbtn.enabled = YES;
//                    _btnNew.enabled = YES;
//                    _privateBtn.enabled = NO;
//                    [_privateBtn setImage:[UIImage imageNamed:NSLocalizedString(@"selected_cus_ch", nil)] forState:Normal];
//                     [_btnNew setImage:[UIImage imageNamed:NSLocalizedString(@"new_img_zh", nil)] forState:Normal];
//                     [_listbtn setImage:[UIImage imageNamed:NSLocalizedString(@"hot_img_zh", nil)] forState:Normal];
//                }
            }
        }
    }
    
    if ([self.delegate respondsToSelector:@selector(clickButton:)]) {
        [self.delegate clickButton:button.tag];
    }
}
- (void)didTapTheMidImageView:(id)object{

    if ([self.delegate respondsToSelector:@selector(clickImageView:)]) {
        [self.delegate clickImageView:object];
    } 
//    NSLog(@"%@", object);
}
//- (NSMutableArray *)imageArray {
//    if (_imageArray == nil) {
//        _imageArray = [NSMutableArray array];
//    }
//    return _imageArray;
//}

@end
